//package com.inspur.edp.bef.dtgenerator.core.rtgen.managergen.b4retrievedtmgen;
//
//import com.inspur.edp.bef.api.attr.BeforeRetrieveDtmsAttribute;
//import com.inspur.edp.bef.api.attr.BeforeRetrieveDtmsExtendAttribute;
//import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
//import com.inspur.edp.caf.generator.field.FieldGenerator;
//import com.inspur.edp.cef.rtgenerator.common.CefMgrTypeInfo;
//import com.inspur.edp.cef.rtgenerator.managergen.ManagerGeneratorContext;
//import com.inspur.edp.cef.spi.determination.IDetermination;
//import org.eclipse.jdt.core.dom.*;
//
//import java.util.ArrayList;
//import java.util.List;
//
//public class B4RetrieveGetDeterminationsFieldGenerator  extends FieldGenerator {
//    private ManagerGeneratorContext entityContext;
//
//    public B4RetrieveGetDeterminationsFieldGenerator(ManagerGeneratorContext entityContext) {
//        this.entityContext = entityContext;
//    }
//
//    @Override
//    protected java.util.ArrayList<Modifier.ModifierKeyword> getAccessModifier() {
//        return new java.util.ArrayList<Modifier.ModifierKeyword>(java.util.Arrays.asList(new Modifier.ModifierKeyword[]{Modifier.ModifierKeyword.PRIVATE_KEYWORD, Modifier.ModifierKeyword.STATIC_KEYWORD}));
//    }
//
//    public static String ItemName = "determinationsList";
//
//    @Override
//    protected String getFieldName() {
//        return ItemName;
//    }
//
//    @Override
//    protected TypeInfo getFieldType() {
//        TypeInfo typeInfo = new TypeInfo(List.class.getTypeName());
//        typeInfo.setIsParameterizedType(true);
//        typeInfo.getArguments().add(new TypeInfo(IDetermination.class));
//        return typeInfo;
//    }
//
//    @Override
//    protected Expression buildGetMethodBody() {
//        ClassInstanceCreation arrayListCreation = ast.newClassInstanceCreation();
//        setFieldType(arrayListCreation);
//        setFieldArguments(arrayListCreation);
//        return arrayListCreation;
//    }
//
//    private void setFieldArguments(ClassInstanceCreation arrayListCreation) {
//        MethodInvocation methodInvocation = ast.newMethodInvocation();
//        setArrayAslistMInvocationExpression(methodInvocation);
//        setArrayAslistMInvocationName(methodInvocation);
//        setArrayAslistMInvocationArguments(methodInvocation);
//        arrayListCreation.arguments().add(methodInvocation);
//    }
//
//    private void setArrayAslistMInvocationArguments(MethodInvocation methodInvocation) {
//        ArrayCreation arrayCreation = ast.newArrayCreation();
//        ArrayType arrayType = ast.newArrayType(new com.inspur.edp.caf.generator.baseInfo.TypeInfo(IDetermination.class).getType(ast));
//        arrayCreation.setType(arrayType);
//        arrayCreation.setInitializer(createArrayInitializer());
//        methodInvocation.arguments().add(arrayCreation);
//    }
//
//    private ArrayInitializer createArrayInitializer() {
//        ArrayInitializer initializer = ast.newArrayInitializer();
//        ArrayList<Class> types = prepareInstance();
//        if (types == null || types.size() == 0)
//            return initializer;
//        for (Class type : types) {
//            ClassInstanceCreation classInstanceCreation = ast.newClassInstanceCreation();
//            classInstanceCreation.setType(new com.inspur.edp.caf.generator.baseInfo.TypeInfo(type).getType(ast));
//            addImport(type.getTypeName());
//            initializer.expressions().add(classInstanceCreation);
//        }
//        return initializer;
//    }
//
//    private void setArrayAslistMInvocationName(MethodInvocation methodInvocation) {
//        methodInvocation.setName(ast.newSimpleName("asList"));
//    }
//
//    private void setArrayAslistMInvocationExpression(MethodInvocation methodInvocation) {
//        QualifiedName name = ast.newQualifiedName(getQualifier(), ast.newSimpleName("Arrays"));
//        methodInvocation.setExpression(name);
//    }
//
//    private Name getQualifier() {
//        return ast.newQualifiedName(ast.newSimpleName("java"), ast.newSimpleName("util"));
//    }
//
//    private void setFieldType(ClassInstanceCreation arrayListCreation) {
//        ParameterizedType arrayListType = ast.newParameterizedType(new com.inspur.edp.caf.generator.baseInfo.TypeInfo(ArrayList.class).getType(ast));
//        arrayListCreation.setType(arrayListType);
//    }
//
//
//    private java.util.ArrayList<BeforeRetrieveDtmsAttribute> getBasicCustomAttributes(java.lang.Class type) {
//        java.util.ArrayList<BeforeRetrieveDtmsAttribute> list = new java.util.ArrayList<BeforeRetrieveDtmsAttribute>();
//        Object[] attributes = type.getDeclaredAnnotationsByType(BeforeRetrieveDtmsAttribute.class);
//        for (Object obj : attributes) {
//            if (obj instanceof BeforeRetrieveDtmsAttribute) {
//                BeforeRetrieveDtmsAttribute da = (BeforeRetrieveDtmsAttribute) ((obj instanceof BeforeRetrieveDtmsAttribute) ? obj : null);
//                if (da != null) {
//                    list.add(da);
//                }
//            }
//        }
//        return list;
//    }
//
//    private java.util.ArrayList<BeforeRetrieveDtmsExtendAttribute> getExtendCustomAttribute(java.lang.Class[] type) {
//        java.util.ArrayList<BeforeRetrieveDtmsExtendAttribute> list = new java.util.ArrayList<BeforeRetrieveDtmsExtendAttribute>();
//        for (java.lang.Class t : type) {
//            Object[] attributes = t.getDeclaredAnnotationsByType(BeforeRetrieveDtmsExtendAttribute.class);
//            for (Object obj : attributes) {
//                if (obj instanceof BeforeRetrieveDtmsExtendAttribute) {
//                    BeforeRetrieveDtmsExtendAttribute da = (BeforeRetrieveDtmsExtendAttribute) ((obj instanceof BeforeRetrieveDtmsExtendAttribute) ? obj : null);
//                    if (da != null) {
//                        list.add(da);
//                    }
//                }
//            }
//        }
//
//        return list;
//    }
//
//    private java.util.ArrayList<BeforeRetrieveDtmsAttribute> getSameLayerAttributes(CefMgrTypeInfo parentTypeInfo) {
//        if (parentTypeInfo == null) {
//            return new java.util.ArrayList<BeforeRetrieveDtmsAttribute>();
//        }
//        java.lang.Class type = parentTypeInfo.getImplType();
//        java.util.ArrayList<BeforeRetrieveDtmsAttribute> list = new java.util.ArrayList<BeforeRetrieveDtmsAttribute>();
//        Object[] attributes = type.getDeclaredAnnotationsByType(BeforeRetrieveDtmsAttribute.class);
//        for (Object obj : attributes) {
//            if (obj instanceof BeforeRetrieveDtmsAttribute) {
//                BeforeRetrieveDtmsAttribute da = (BeforeRetrieveDtmsAttribute) ((obj instanceof BeforeRetrieveDtmsAttribute) ? obj : null);
//                if (da != null) {
//                    list.add(da);
//                }
//            }
//        }
//        return list;
//    }
//
//    private ArrayList<Class> prepareInstance() {
//        java.util.ArrayList<CefMgrTypeInfo> infoList = entityContext.getProjContext().getMgrTypes();
//        java.util.ArrayList<BeforeRetrieveDtmsAttribute> daList = getBasicCustomAttributes(entityContext.getProjContext().getCurrentTypeInfo().getImplType());
//        //.getEntityEntityTypeInfos().get("RootNode").getActionImplType());
//        int capacity = infoList.size() - 1;
//        java.lang.Class[] dearray = new java.lang.Class[capacity];
//        for (int i = 0; i < capacity; i++) {
//            //TODO: extend也应该从be实现类上找
//            dearray[i] = infoList.get(i + 1).getImplType();
//        }
//        java.util.ArrayList<BeforeRetrieveDtmsExtendAttribute> deaList = getExtendCustomAttribute(dearray);
//        java.util.ArrayList<BeforeRetrieveDtmsAttribute> daLayerList = getSameLayerAttributes(entityContext.getProjContext().getParentTypeInfo());
//        java.util.ArrayList<java.lang.Class> result = new java.util.ArrayList<java.lang.Class>();
//
//        for (BeforeRetrieveDtmsExtendAttribute dea : deaList) {
//            if (dea.beforeDeterminations() != null) {
//                for (java.lang.Class type : dea.beforeDeterminations()) {
//                    result.add(type);
//                }
//            }
//        }
//        for (BeforeRetrieveDtmsAttribute da : daList) {
//            if (da.value() != null) {
//                for (java.lang.Class type : da.value()) {
//                    result.add(type);
//                }
//            }
//        }
//        for (BeforeRetrieveDtmsExtendAttribute dea : deaList) {
//            if (dea.afterDeterminations() != null) {
//                for (java.lang.Class type : dea.afterDeterminations()) {
//                    result.add(type);
//                }
//            }
//        }
////		for (DeterminationsAttribute da : daLayerList)
////		{
////			if (da.determinations() != null)
////			{
////				for (java.lang.Class type : da.determinations())
////				{
////					result.add(type);
////				}
////			}
////		}
//        return result;
//    }
//}